-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
44 lines (35 loc) · 901 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n, x;
n = sc.nextInt();
for (int i = 0; i < n; i++) {
x = sc.nextInt();
if (EPrimo(x))
System.out.println("Prime");
else
System.out.println("Not Prime");
}
sc.close();
}
public static boolean EPrimo(int x) {
int i;
double raiz;
if (x == 2)
return true;
else if (x % 2 == 0)
return false;
else {
i = 3;
raiz = Math.sqrt(x);
while (i <= raiz) {
if (x % i == 0)
return false;
i = i + 2;
}
}
return true;
}
}